use lazy_static::lazy_static;
use serde::Serialize;
use tera::{Context, Tera};

lazy_static! {
    pub static ref TEMPLATES: Tera = {
        let tera = match Tera::new("res/templates/**/*.html") {
            Ok(t) => t,
            Err(e) => {
                println!("Parsing error(s): {}", e);
                ::std::process::exit(1);
            }
        };
        tera
    };
}

fn main() {
    println!("Hello, world!");

    render_index_html().unwrap()
}

#[derive(Serialize)]
struct Product {
    name: String
}

fn render_index_html() -> anyhow::Result<()> {
    let product = Product { name: "杯子".to_string() };

    TEMPLATES.render("products/product.html", &Context::from_serialize(&product)?)?;

    Ok(())
}
